package com.itawei.TCPpractise.num2;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 客户端：多次发送数据
 * 服务器：接收多次接收数据 并打印
 */
public class Server {
    public static void main(String[] args) throws IOException {
        //1.创建一个socket对象
        ServerSocket ss = new ServerSocket(10086);//链接端口
        //2.等待客户端链接
        Socket socket = ss.accept();
        //3.获取输入流
        InputStream is = socket.getInputStream();
        //4.转成字符流
        InputStreamReader isr = new InputStreamReader(is);
        int b;
        //5.读取数据
        while((b = isr.read()) != -1){
            System.out.print((char)b);
        }

        //6.回写数据
        OutputStream os = socket.getOutputStream();
        os.write("亲爱的渡边博子小姐，你收到我的信了吗？".getBytes());

        //6.释放资源
        socket.close();
    }
}
